<?php

/**
 * client助手
 */

class Helper_Client extends YOU{

	/** 获取客户端ip **/
	public function getip ()
	{
		if(getenv('HTTP_CLIENT_IP')) {
			$onlineip = getenv('HTTP_CLIENT_IP');
		} elseif(getenv('HTTP_X_FORWARDED_FOR')) {
			list($onlineip) = explode(',', getenv('HTTP_X_FORWARDED_FOR'));
		} elseif(getenv('REMOTE_ADDR')) {
			$onlineip = getenv('REMOTE_ADDR');
		} else {
			$onlineip = $HTTP_SERVER_VARS['REMOTE_ADDR'];
		}
		return $onlineip;
	}

	/** 获取当前页完整url地址 **/
	function getUrl ($url = '')
	{
		if (empty($url)) {
			return 'http://'.$_SERVER[SERVER_NAME].$_SERVER[REQUEST_URI];
		} else {
			return $url = 'index.php?a='.$url;
		}
	}

	function alert($msg)
	{
		echo "<script>alert('".$msg."');history.back();</script>";
		exit();
	}

	function exitClose($msg)
	{
		echo "<script>alert('".$msg."');window.close();</script>";
		exit();
	}

	function location($msg, $url)
	{
		if (empty($url)) $url = $_SERVER[HTTP_REFERER];
		echo "<script>alert('".$msg."');location.href = '".$url."';</script>";
		exit();
	}

	function reurl($url)
	{
		if (empty($url)) $url = $_SERVER[HTTP_REFERER];
		echo "<script>location.href = '".$url."';</script>";
		exit();
	}
}

